const path = require('path');
const HtmlWebpackPlugin = require('html-webpack-plugin')
const Webpack = require('webpack')

module.exports = {
  // devServer:{
  //   open:true,
  //   port:3000,
  //   contentBase:'./public/index.html'
  // },
  entry: {
    // 前台
    index: './public/assets/js/index',  //打包入口项
    list: './public/assets/js/list',
    search: './public/assets/js/search',
    detail: './public/assets/js/detail',
    jquery: './public/assets/vendors/jquery/jquery.min.js',
    // 后台
  },
  output: {
    path: path.join(__dirname, './dist'),
    filename: '[name].bundle.js',  //多入口写法--打包出同名文件

  },
  module: {
    rules: [
      { test: /\.css$/, use: ['style-loader', 'css-loader'] },
      { test: /\.less/, use: ['style-loader', 'css-loader', "less-loader"] },
      { test: /\.(png|jpg|eot|svg|ttf|woff|woff2)$/, use: ['url-loader'] },
      { test: /\.html$/, use: ['html-loader'] },
      
    ],
  },
  plugins: [
    //后台
    //前台
    new Webpack.ProvidePlugin({
      $: 'jquery'  //全局暴露的第三方库      .不写内置模块的话，报$ is not defined
    }),
    new HtmlWebpackPlugin({
      filename: 'index.html',
      template: path.join(__dirname, './public/index.html'),
      chunks: ['index']          //多入口写法--按需导入
    }),
    new HtmlWebpackPlugin({
      filename: 'list.html',
      template: path.join(__dirname, './public/list.html'),
      chunks: ['list']
    }),
    new HtmlWebpackPlugin({
      filename: 'search.html',
      template: path.join(__dirname, './public/search.html'),
      chunks: ['search']
    }),
    new HtmlWebpackPlugin({
      filename: 'detail.html',
      template: path.join(__dirname, './public/detail.html'),
      chunks: ['detail']
    })

  ],
  resolve: {
    alias: {
      '@': path.join(__dirname, './public')
    },
    extensions: ['.js', '.json', '.css']
  }
}